package Navigator;

import Navigator.student.StudentDao;
import Worker.WorkerDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ServletNav")
public class ServletNav extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           String post=request.getParameter("post");
           String workerNo=request.getParameter("workerNo");
           String workPas=request.getParameter("pas");
           switch (post){
               case "1":    //学生登陆
                   StudentDao studentDao=new StudentDao();
                   String flag=studentDao.getLogin(workerNo,workPas);
                   if(flag!=null){
                       response.sendRedirect("/Students/StudentNav.jsp?studentNo="+workerNo);
                   }else {
                       response.getWriter().println("登陆出错,请后退重试112"+flag);
                   }
                   break;
               case "2":    //教师登录
                   WorkerDao workerDao=new WorkerDao();
                   String workerName=workerDao.getLogin(workerNo,workPas,"教师");
                   if(workerName==null){
                       response.sendRedirect("登录错误，请退出重试");
                   }else {
                       response.sendRedirect("/Teachers/TeacherNav.jsp?workerNo="+workerNo);
                   }
                   break;
               case "3":    //系统管理员登录
                   WorkerDao workerDao2=new WorkerDao();
                   String workerName2=workerDao2.getLogin(workerNo,workPas,"系统管理员");
                   if(workerName2==null){
                       response.sendRedirect("登录错误，请退出重试");
                   }else {
                       response.sendRedirect("/SystemerNav/SystemerNav.jsp?workerNo="+workerNo);
                   }
                   break;
               case "4":     //教务员登录
                   WorkerDao workerDao1=new WorkerDao();
                   String workerName1=workerDao1.getLogin(workerNo,workPas,"教务员");
                   if(workerName1==null){
                       response.getWriter().println("登录错误，请退出重试");
                   }else {
                       response.sendRedirect("/educateOffice/educateOfficeNav.jsp?workerNo="+workerNo);
                   }
           }
    }
}
